load("@rules_cc//cc:defs.bzl", "cc_test")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "meson")
load("@rules_shell//shell:sh_test.bzl", "sh_test")

meson(
    name = "meson_lib",
    build_data = ["//meson_simple/code:clang_wrapper.sh"],
    env = select({
        "//:windows": {
            "CLANG_WRAPPER": "$(execpath //meson_simple/code:clang_wrapper.sh)",
            "CXX_FLAGS": "/MD",
        },
        "//conditions:default": {
            "CLANG_WRAPPER": "$(execpath //meson_simple/code:clang_wrapper.sh)",
            "CXX_FLAGS": "-fPIC",
        },
    }),
    lib_source = "//meson_simple/code:srcs",
    out_static_libs = ["liba.a"],
)

cc_test(
    name = "test_lib",
    srcs = [
        "test_libb.cpp",
    ],
    deps = [
        ":meson_lib",
    ],
)

meson(
    name = "meson_lib-introspect",
    lib_source = "//meson_simple/code:srcs",
    out_data_files = ["introspect.json"],
    out_include_dir = "",
    targets = ["introspect"],
)

sh_test(
    name = "test_introspect",
    srcs = ["test_introspect.sh"],
    args = ["$(location meson_lib-introspect)"],
    data = [":meson_lib-introspect"],
    deps = ["@bazel_tools//tools/bash/runfiles"],
)
